﻿using System.Collections;
using IDAL;
using Model;
using System.Collections.Generic;

namespace BLL
{
    /// <summary>
    /// User关注层
    /// </summary>
    public class UserRelationService
    {
        private static  IUserRelationDAL dal = DALFactory.DataAccess.createUserRelationDAL();
        
        //添加关注
        public Hashtable addRelation(string who, string follow)
        {
            UserService u = new UserService();
            UserRelation ur = dal.getUserRelation(u.getUserByEmail(who), u.getUserByEmail(follow));
            if(who.Equals(follow))
            {
                Hashtable ht = new Hashtable();
                ht.Add("result", "3");
                return ht;
            }
            else if (ur != null)
            {
                Hashtable ht = new Hashtable();
                ht.Add("result", "2");
                return ht;
            }
            else
            {
                ur = new UserRelation();
                ur.who = u.getUserByEmail(who);
                ur.follow = u.getUserByEmail(follow);
                dal.saveUserRelation(ur);
                Hashtable ht = new Hashtable();
                ht.Add("result", "1");
                return ht;
            }
        }

        //取消关注
        public Hashtable DelRelation(string who, string follow)
        {
            UserService u = new UserService();
            UserRelation ur = dal.getUserRelation(u.getUserByEmail(who), u.getUserByEmail(follow));
            if (null == ur)
            {
                Hashtable ht = new Hashtable();
                ht.Add("result", "2");
                return ht;
            }
            else
            {
                dal.delateUserRelation(ur);
                Hashtable ht = new Hashtable();
                ht.Add("result", "1");
                return ht;
            }
        }

        //得到关注列表
        public IList<UserRelation> GetUserRelations(string name)
        { 
            UserService u = new UserService();
            return dal.getUserRelation(u.getUserByEmail(name));
        }

        public IList<UserRelation> GetUserRelationsFollow(string name)
        {
            UserService u = new UserService();
            return dal.getUserRelationFollow(u.getUserByEmail(name));
        }
    }
}
